package com.xiaotao.config;

import com.xiaotao.util.ConstantUtil;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {
    //延迟取消订单交换机队列
    @Bean
    public CustomExchange checkOrderExchange(){
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type","topic");
        return new CustomExchange(ConstantUtil.EXCHANGE_DELAY_CHECK_ORDER,"x-delayed-message",true,false,map);

    }
    @Bean
    public Queue checkOrderQueue(){
        return new Queue(ConstantUtil.QUEUE_DELAY_CHECK_ORDER);
    }
    @Bean
    public Binding checkOrderQueueToCheckOrderExchange(){
        return BindingBuilder.bind(checkOrderQueue()).to(checkOrderExchange()).with(ConstantUtil.ROUTEING_KEY_DELAY_ORDER).noargs();
    }

    //创建订单交换机和队列
    @Bean
    public TopicExchange createOrderTopicExchange(){
        return new TopicExchange(ConstantUtil.EXCHANGE_CREATE_ORDER);
    }

    @Bean
    public Queue createOrderQueue(){
        return new Queue(ConstantUtil.QUEUE_CREATE_ORDER);
    }

    @Bean
    public Binding createOrderQueueToKillOrderTopicExchange(){
        return BindingBuilder.bind(createOrderQueue()).to(createOrderTopicExchange()).with(ConstantUtil.ROUTEING_KEY_CREATE_ORDER);
    }
}
